/**
 * 
 */
package com.miolr.module.core.dao;

import java.util.List;
import java.util.Set;

import org.springframework.stereotype.Repository;

import com.miolr.core.dao.hibernate.HibernateGenericDao;
import com.miolr.module.core.model.SocialConnection;

/**
 * @author iday
 * 
 */
@Repository
public class SocialConnectionDao extends HibernateGenericDao<SocialConnection> {

	public List<SocialConnection> findConnectedTo(String providerId,
			Set<String> providerUserIds) {
		return this
				.findAll(
						"from SocialConnection where providerId=? and providerUserId in ?",
						true, providerId, providerUserIds);
	}

	public List<SocialConnection> findConnectedTo(String providerId,
			String providerUserId) {
		return this
				.findAll(
						"from SocialConnection where providerId=? and providerUserId=?",
						true, providerId, providerUserId);
	}

	public List<SocialConnection> findByUserId(String userId) {
		return this
				.findAll(
						"from SocialConnection where userId=? order by providerId, rank",
						true, userId);
	}

	public List<SocialConnection> findByUserId(String providerId, String userId) {
		return this
				.findAll(
						"from SocialConnection where providerId=? and userId=? order by rank",
						true, providerId, userId);
	}
	
	public SocialConnection find(String providerId, String providerUserId, String userId) {
		return this
				.findOne(
						"from SocialConnection where providerId=? and providerUserId=? and userId=?",
						true, providerId, providerUserId, userId);
	}
	
	public SocialConnection findPrimary(String providerId, String userId) {
		return this
				.findOne(
						"from SocialConnection where providerId=? and userId=? and rank=1",
						true, providerId, userId);
	}

}
